macos: handle point conversion on older macOS
authorChristian Hergert <chergert@redhat.com>
Tue, 5 Jan 2021 21:52:11 +0000 (13:52 -0800)
committerChristian Hergert <chergert@redhat.com>
Tue, 5 Jan 2021 21:52:11 +0000 (13:52 -0800)
On older systems, the availability of some methods seem to be incorrect
based on Apple documentation. This works around the issue by using
the rect conversion on older systems.

gdk/macos/GdkMacosWindow.c
gdk/macos/gdkmacosdisplay-translate.c
gdk/macos/gdkmacosutils-private.h

index e85ebf8805115c12b254af09aafd35d41448493d..f4fcd01ad54b9737f9c37a08eb93eb376ebcc8c6 100644 (file)
 
   inTrackManualResize = YES;
 
-  mouse_location = [self convertPointToScreen:[self mouseLocationOutsideOfEventStream]];
+  mouse_location = convert_nspoint_to_screen (self, [self mouseLocationOutsideOfEventStream]);
   mdx = initialResizeLocation.x - mouse_location.x;
   mdy = initialResizeLocation.y - mouse_location.y;
 
     }
 
   initialResizeFrame = [self frame];
-  initialResizeLocation = [self convertPointToScreen:[self mouseLocationOutsideOfEventStream]];
+  initialResizeLocation = convert_nspoint_to_screen (self, [self mouseLocationOutsideOfEventStream]);
 }
 
 -(NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
index b638b87ab9da0012452164505bac3a1c71c6656b..e6551581a2075be605d65bd6cd251f563b04dce7 100644 (file)
@@ -700,7 +700,7 @@ get_surface_point_from_screen_point (GdkSurface *surface,
   NSPoint point;
 
   nswindow = _gdk_macos_surface_get_native (GDK_MACOS_SURFACE (surface));
-  point = [nswindow convertPointFromScreen:screen_point];
+  point = convert_nspoint_from_screen (nswindow, screen_point);
 
   *x = point.x;
   *y = surface->height - point.y;
@@ -821,7 +821,7 @@ get_surface_from_ns_event (GdkMacosDisplay *self,
         }
       else
         {
-          *screen_point = [(GdkMacosWindow *)[nsevent window] convertPointToScreen:point];
+          *screen_point = convert_nspoint_to_screen ([nsevent window], point);
           *x = point.x;
           *y = surface->height - point.y;
         }
index 6b81fd28acc62c564da795129e3bbd5a1e2ae1c7..dd8d3b296aaa3cbb20e82ade25a23735459de99f 100644 (file)
@@ -40,5 +40,36 @@ struct _GdkPoint
 };
 typedef struct _GdkPoint GdkPoint;
 
+static inline NSPoint
+convert_nspoint_from_screen (NSWindow *window,
+                             NSPoint   point)
+{
+#ifdef AVAILABLE_MAC_OS_X_VERSION_10_15_AND_LATER
+  return [window convertPointFromScreen:point];
+#else
+  /* Apple documentation claims that convertPointFromScreen is available
+   * on 10.12+. However, that doesn't seem to be the case when using it.
+   * Instead, we'll just use it on modern 10.15 systems and fallback to
+   * converting using rects on older systems.
+   */
+  return [window convertRectFromScreen:NSMakeRect (point.x, point.y, 0, 0)].origin;
+#endif
+}
+
+static inline NSPoint
+convert_nspoint_to_screen (NSWindow *window,
+                           NSPoint   point)
+{
+#ifdef AVAILABLE_MAC_OS_X_VERSION_10_15_AND_LATER
+  return [window convertPointToScreen:point];
+#else
+  /* Apple documentation claims that convertPointToScreen is available
+   * on 10.12+. However, that doesn't seem to be the case when using it.
+   * Instead, we'll just use it on modern 10.15 systems and fallback to
+   * converting using rects on older systems.
+   */
+  return [window convertRectToScreen:NSMakeRect (point.x, point.y, 0, 0)].origin;
+#endif
+}
 
 #endif /* __GDK_MACOS_UTILS_PRIVATE_H__ */